home *** CD-ROM | disk | FTP | other *** search
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Form;
- import javax.microedition.lcdui.Graphics;
-
- public class PainterCanvas extends Canvas implements CommandListener {
- private final int SIZE = 9;
- public static final int IMG_WIDTH = 96;
- public static final int IMG_HEIGHT = 46;
- private Form form;
- private Painter midlet;
- private String name;
- // $FF: renamed from: x int
- private int field_0;
- // $FF: renamed from: y int
- private int field_1;
- private int startX;
- private int startY;
- private int col;
- private int row;
- private boolean preview;
- private boolean[][] bitmap = new boolean[96][46];
- private Command saveCommand;
- private Command previewCommand;
- private Command cancelCommand;
-
- public PainterCanvas(Painter var1, Form var2, String var3) {
- this.midlet = var1;
- this.form = var2;
- this.name = var3;
- this.saveCommand = new Command("Save", 1, 1);
- this.previewCommand = new Command("Preview", 1, 2);
- this.cancelCommand = new Command("Finish", 1, 3);
- ((Displayable)this).addCommand(this.saveCommand);
- ((Displayable)this).addCommand(this.previewCommand);
- ((Displayable)this).addCommand(this.cancelCommand);
- ((Displayable)this).setCommandListener(this);
- Painter.fontHeight = Font.getDefaultFont().getHeight();
- Painter.width = ((Canvas)this).getWidth();
- Painter.height = ((Canvas)this).getHeight() - Painter.fontHeight;
- this.field_0 = 0;
- this.field_1 = 0;
- this.startX = 0;
- this.startY = 0;
- this.col = Painter.width / 8;
- this.row = Painter.height / 8;
- if (this.name != null) {
- Store.load(this.name, this.bitmap);
- }
-
- ((Canvas)this).repaint();
- ((Canvas)this).serviceRepaints();
- }
-
- public void clearScreen(Graphics var1) {
- var1.setColor(16777215);
- var1.fillRect(0, 0, Painter.width, Painter.height + Painter.fontHeight);
- }
-
- public void commandAction(Command var1, Displayable var2) {
- if (var1.equals(this.saveCommand)) {
- if (this.name != null) {
- Store.save(this.name, this.bitmap);
- } else {
- SaveForm var3 = new SaveForm(this.midlet, this, this.bitmap);
- this.midlet.display.setCurrent(var3);
- }
- } else if (var1.equals(this.previewCommand)) {
- Preview var4 = new Preview(this.midlet, this, this.bitmap);
- this.midlet.display.setCurrent(var4);
- } else if (var1.equals(this.cancelCommand)) {
- this.midlet.display.setCurrent(this.form);
- }
-
- }
-
- public void keyPressed(int var1) {
- var1 = ((Canvas)this).getGameAction(var1);
- switch (var1) {
- case 1:
- if (this.field_1 > 0) {
- if (this.field_1 == this.startY) {
- --this.startY;
- }
-
- --this.field_1;
- }
- break;
- case 2:
- if (this.field_0 > 0) {
- if (this.field_0 == this.startX) {
- --this.startX;
- }
-
- --this.field_0;
- }
- case 3:
- case 4:
- case 7:
- default:
- break;
- case 5:
- if (this.field_0 < 95) {
- if (this.field_0 == this.startX + this.col - 1) {
- ++this.startX;
- }
-
- ++this.field_0;
- }
- break;
- case 6:
- if (this.field_1 < 45) {
- if (this.field_1 == this.startY + this.row - 1) {
- ++this.startY;
- }
-
- ++this.field_1;
- }
- break;
- case 8:
- this.bitmap[this.field_0][this.field_1] ^= true;
- }
-
- ((Canvas)this).repaint();
- ((Canvas)this).serviceRepaints();
- }
-
- public void paint(Graphics var1) {
- Font var2 = Font.getDefaultFont();
- this.clearScreen(var1);
- var1.setColor(0);
-
- for(int var3 = 0; var3 < this.col; ++var3) {
- for(int var4 = 0; var4 < this.row; ++var4) {
- var1.drawRect(var3 * 8, var4 * 8, 9, 9);
- if (this.bitmap[var3 + this.startX][var4 + this.startY]) {
- var1.fillRect(var3 * 8 + 3, var4 * 8 + 3, 4, 4);
- }
- }
- }
-
- var1.drawLine((this.field_0 - this.startX) * 8 + 4, (this.field_1 - this.startY) * 8 - 2, (this.field_0 - this.startX) * 8 + 4, (this.field_1 - this.startY + 1) * 8 + 2);
- var1.drawLine((this.field_0 - this.startX) * 8 + 4 + 1, (this.field_1 - this.startY) * 8 - 2, (this.field_0 - this.startX) * 8 + 4 + 1, (this.field_1 - this.startY + 1) * 8 + 2);
- var1.drawLine((this.field_0 - this.startX) * 8 - 2, (this.field_1 - this.startY) * 8 + 4, (this.field_0 - this.startX + 1) * 8 + 2, (this.field_1 - this.startY) * 8 + 4);
- var1.drawLine((this.field_0 - this.startX) * 8 - 2, (this.field_1 - this.startY) * 8 + 4 + 1, (this.field_0 - this.startX + 1) * 8 + 2, (this.field_1 - this.startY) * 8 + 4 + 1);
- String var5 = "X=" + this.field_0 + " Y=" + this.field_1;
- var1.drawString(var5, 0, Painter.height, 20);
- }
- }
-